<?php
class content_commonModel extends baseModel{
	protected $table = 'content';

    //访问计数
    public function views_content($aid,$views){
        $data['views'] = $views + 1;
        $condition['aid'] = $aid;
        $this->update($condition,$data);
    }

    //上一篇
    public function prev_content($aid,$category){
        //内容信息SQL接口
        $ext_sql='';
        $ext_field='';
        $ext_where='';
        $api_sql=ApiHook('hook_content_prev_sql',$category);
        if(!empty($api_sql)){
            foreach ($api_sql as $value) {
                $ext_sql.=$value['sql'];
                $ext_field.=$value['field'];
                $ext_where.=$value['where'];
            }
        }
        $info="
            SELECT {$$ext_field}A.*
             FROM {$this->model->pre}content A 
             LEFT JOIN {$this->model->pre}category B ON B.cid = A.cid
             {$$ext_sql}
             WHERE A.aid<{$aid} AND A.status=1 AND B.cid={$category['cid']}{$ext_where} ORDER BY A.aid desc LIMIT 1
            ";
            $info=$this->model->query($info);
        return $info[0]; 
    }

    //下一篇
    public function next_content($aid,$category){
        //内容信息SQL接口
        $ext_sql='';
        $ext_field='';
        $ext_where='';
        $api_sql=ApiHook('hook_content_next_sql',$category);
        if(!empty($api_sql)){
            foreach ($api_sql as $value) {
                $ext_sql.=$value['sql'];
                $ext_field.=$value['field'];
                $ext_where.=$value['where'];
            }
        }
        $info="
            SELECT {$expand_field}A.*
             FROM {$this->model->pre}content A 
             LEFT JOIN {$this->model->pre}category B ON B.cid = A.cid
             {$expand}
             WHERE A.aid>{$aid} AND A.status=1 AND B.cid={$category['cid']}{$ext_where} ORDER BY A.aid asc LIMIT 1
            ";
            $info=$this->model->query($info);
        return $info[0];
    }
}